package cn.com.sparkle.paxos;

public class ConfigNode {
	private String ip;
	private String port;
	private String clientPort;

	public ConfigNode(String ip, String port, String clientPort) {
		super();
		this.ip = ip;
		this.port = port;
		this.clientPort = clientPort;
	}

	@Override
	public int hashCode() {
		return (ip + ":" + port).hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ConfigNode) {
			ConfigNode s = (ConfigNode) obj;
			return ip.equals(s.ip) && port.endsWith(s.port);
		}
		return false;
	}

	public String getIp() {
		return ip;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getClientPort() {
		return clientPort;
	}

	public void setClientPort(String clientPort) {
		this.clientPort = clientPort;
	}

	public String toString() {
		return ip + ":" + port + ":" + clientPort;
	}

	public static ConfigNode parseNode(String address) {
		String[] array = address.trim().split(":");
		return new ConfigNode(array[0], array[1], array.length == 3 ? array[2]
				: "");
	}
}
